//package com.neu.his.interceptor;
//
//import com.alibaba.fastjson.JSON;
//import com.neu.his.constrant.GlobalConstrant;
//import com.neu.his.constrant.ResultConstrant;
//import com.neu.his.core.Result;
//import com.neu.his.utils.JwtUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.lang.Nullable;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//
//@Slf4j
//public class LoginInterceptor implements HandlerInterceptor {
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String path = request.getServletPath();
//        if(StringUtils.isNotEmpty(path)&&path.contains("/auth/login")){
//            return true;
//        }
//        // 1. 带有令牌 10
//        String token = request.getHeader("token");
//        if (StringUtils.isEmpty(token)) {
//            Result result = Result.fail(ResultConstrant.TOKEN_ERROR, "token error");
//            response.getWriter().write(JSON.toJSONString(result));
//            response.getWriter().close();
//            return false;
//        } else {
//            String UserName = JwtUtils.getUserName(token);
//            if (JwtUtils.verify(token, UserName, GlobalConstrant.TOKEN_SECRET)) {
//                return true;
//            } else {
//                Result result = Result.fail(ResultConstrant.TOKEN_ERROR, "token error");
//                response.getWriter().write(JSON.toJSONString(result));
//                return false;
//            }
//        }
//    }
//
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
//        log.info("响应拦截器");
//    }
//
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
//        log.info("后置拦截器");
//    }
//}
